import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '我的',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
            seedColor: const Color.fromARGB(255, 255, 2, 2)),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text(
            '主页',
            style: TextStyle(fontSize: 18),
          ),
        ),
        body: MyBody(),
      ),
    );
  }
}

class MyBody extends StatelessWidget {
  const MyBody({super.key});

  @override
  Widget build(BuildContext context) {
    return WrapDemo("点我");
  }
}

class WrapDemo extends StatelessWidget {
  final String text;

  WrapDemo(this.text, {super.key});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(10),
      // Wrap组件，子组件超出父组件宽度时自动换行
      child: Wrap(
        // 水平间距
        spacing: 10,
        // 垂直间距
        runSpacing: 8,
        // 主轴方向
        // direction: Axis.vertical,
        // 子组件对齐方式
        // alignment: WrapAlignment.center,
        children: [
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
          ElevatedButton(
            onPressed: () {
              print("不要点我");
            },
            child: Text(text),
          ),
        ],
      ),
    );
  }
}
